package com.ruoyi.project.device.roadway.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.device.roadway.domain.BasRoadway;
import com.ruoyi.project.device.roadway.service.IBasRoadwayService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巷道管理Controller
 * 
 * @author wld
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/device/roadway")
public class BasRoadwayController extends BaseController
{
    private String prefix = "device/roadway";

    @Autowired
    private IBasRoadwayService basRoadwayService;

    @GetMapping()
    public String roadway()
    {
        return prefix + "/roadway";
    }

    /**
     * 查询巷道管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasRoadway basRoadway)
    {
        startPage();
        List<BasRoadway> list = basRoadwayService.selectBasRoadwayList(basRoadway);
        return getDataTable(list);
    }

    /**
     * 导出巷道管理列表
     */
    @Log(title = "巷道管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasRoadway basRoadway)
    {
        List<BasRoadway> list = basRoadwayService.selectBasRoadwayList(basRoadway);
        ExcelUtil<BasRoadway> util = new ExcelUtil<BasRoadway>(BasRoadway.class);
        return util.exportExcel(list, "巷道管理数据");
    }

    /**
     * 新增巷道管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存巷道管理
     */
    @Log(title = "巷道管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasRoadway basRoadway)
    {
        return toAjax(basRoadwayService.insertBasRoadway(basRoadway));
    }

    /**
     * 修改巷道管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasRoadway basRoadway = basRoadwayService.selectBasRoadwayById(id);
        mmap.put("basRoadway", basRoadway);
        return prefix + "/edit";
    }

    /**
     * 修改保存巷道管理
     */
    @Log(title = "巷道管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasRoadway basRoadway)
    {
        return toAjax(basRoadwayService.updateBasRoadway(basRoadway));
    }

    /**
     * 删除巷道管理
     */
    @Log(title = "巷道管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basRoadwayService.deleteBasRoadwayByIds(ids));
    }
}
